//
//  ShowMessageTool.m
//  mallbuilderIOS
//
//  Created by yuanfeng on 15/11/19.
//  Copyright © 2015年 yuanfeng01. All rights reserved.
//

#import "ShowMessageTool.h"


@implementation ShowMessageTool
{
    JGProgressHUDStyle _style;
    JGProgressHUDInteractionType _interaction;
    BOOL _zoom;
    BOOL _dim;
    BOOL _shadow;
    JGProgressHUD *refresh;
}

- (JGProgressHUD *)prototypeHUD {
    JGProgressHUD *HUD = [[JGProgressHUD alloc] initWithStyle:_style];
    HUD.interactionType = _interaction;
    
    if (_zoom) {
        JGProgressHUDFadeZoomAnimation *an = [JGProgressHUDFadeZoomAnimation animation];
        HUD.animation = an;
    }
    
    if (_dim) {
        HUD.backgroundColor = [UIColor colorWithWhite:0.0f alpha:0.1f];
    }
    
    if (_shadow) {
        HUD.HUDView.layer.shadowColor = [UIColor blackColor].CGColor;
        HUD.HUDView.layer.shadowOffset = CGSizeZero;
        HUD.HUDView.layer.shadowOpacity = 0.4f;
        HUD.HUDView.layer.shadowRadius = 8.0f;
    }
    
    HUD.delegate = self;
    
    return HUD;
}
-(void)showSimpleHUD:(UIView *)NavView time:(CGFloat)time{
    refresh = self.prototypeHUD;
    [refresh showInView:NavView];
    [refresh dismissAfterDelay:time];
}
-(void)dismiss
{
    [refresh dismiss];
}


+(void)showMessage:(UIView*)view andStr:(NSString *)str
{
    JGProgressHUD *HUD = [JGProgressHUD progressHUDWithStyle:JGProgressHUDStyleDark];
    HUD.textLabel.text =str;
    HUD.indicatorView = [[JGProgressHUDErrorIndicatorView alloc] init];
    [HUD showInView:view];
    [HUD dismissAfterDelay:0.5];
}
+(void)showSucess:(UIView *)view andStr:(NSString *)content
{
    JGProgressHUD *HUD = [JGProgressHUD progressHUDWithStyle:JGProgressHUDStyleDark];
    HUD.textLabel.text =content;
    HUD.indicatorView = [[JGProgressHUDSuccessIndicatorView alloc] init];
    [HUD showInView:view];
    [HUD dismissAfterDelay:0.1];
}

- (void)setHUDStyle:(UISegmentedControl *)c {
    _style = c.selectedSegmentIndex;
}

- (void)setInteraction:(UISegmentedControl *)c {
    _interaction = c.selectedSegmentIndex;
}

- (void)setZoom:(UISegmentedControl *)c {
    _zoom = c.selectedSegmentIndex;
}

- (void)setDim:(UISwitch *)s {
    _dim = s.on;
}

- (void)setShadow:(UISwitch *)s {
    _shadow = s.on;
}


/**
 *  MBProgressHUD只显示文字
 *
 *  @param text  文字描述
 *  @param view  参照view
 *  @param delay 时延
 */
+(void)MBShowText:(NSString *)text andShowView:(UIView *)view andDelay:(CGFloat)delay
{
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.mode = MBProgressHUDModeText;
    hud.labelText =text;
    hud.margin = 20.f;
    hud.removeFromSuperViewOnHide = YES;
    [hud hide:YES afterDelay:delay];
}
@end
